
import { Component, OnInit, Injector, AfterViewInit, OnDestroy, ViewChild, HostBinding, TemplateRef, ElementRef, ViewContainerRef, NgModuleFactory, Input, ComponentRef} from '@angular/core';
import { BehaviorSubject, of, Subject } from 'rxjs';
import { map, filter, switchMap } from 'rxjs/operators';
import { Form, FrameEvent, FrameEventBus, FrameComponent, FARRIS_DEVKIT_FRAME_PROVIDERS, ViewModel, COMMAND_HANDLERS_TOKEN, FRAME_ID, StateMachine, BindingData, Repository, UIState, NgSubscription, Declaration, EXCEPTION_HANDLER, NAMESPACE } from '@farris/devkit';
import { FARRIS_COMMAND_SERVICE_FRAME_PROVIDERS, ComponentManagerService } from '@farris/command-services';
import { KeybindingService } from '@farris/command-services';
import { ActivatedRoute, ParamMap, Router } from '@angular/router';
import { FrmI18nSettingService } from '@gsp-sys/rtf-common';
import { DomSanitizer } from '@angular/platform-browser';

import { FocusInvalidService } from '@farris/command-services';

import { BefLookupRestService, DefaultComboHttpService } from '@farris/bef';
import { ServerSideToken } from '@farris/ui-lookup';
import { ComboServerSideToken } from '@farris/ui-combo-list';
import { WizardService, FarrisPageDetailComponent } from '@farris/ui-wizard';
import { LocalizationService } from "@farris/command-services";
import { __decorate, __metadata } from 'tslib';

import { HzhbxxsV4dmViewmodel } from '../../viewmodels/hzhbxxsv4dmviewmodel';
import { HzhbxxRepository } from '../../models/hzhbxxrepository';
import { LangService } from '../../lang/lang-pipe';

import { HzhbxxsV4dmViewmodelForm } from '../../viewmodels/form/hzhbxxsv4dmviewmodelform';
import { HzhbxxsV4dmViewmodelUIState } from '../../viewmodels/uistate/hzhbxxsv4dmviewmodeluistate';

@Component({
    selector: 'app-hzhbxxsv4dmcomponent',
    templateUrl: './hzhbxxsv4dmcomponent.html',
    styleUrls: ['./hzhbxxsv4dmcomponent.scss'],
    providers: [
        FARRIS_DEVKIT_FRAME_PROVIDERS,
        FARRIS_COMMAND_SERVICE_FRAME_PROVIDERS,
        { provide: FRAME_ID, useValue: 'hzhbxxs-v4dm-component' },
        { provide: BindingData, useClass: BindingData },
        { provide: Repository, useExisting: HzhbxxRepository },
        LangService,
        { provide: NAMESPACE, useValue: '' },
    
        { provide: ServerSideToken, useClass: BefLookupRestService },
        { provide: ComboServerSideToken, useClass: DefaultComboHttpService },
        { provide: Form, useClass: HzhbxxsV4dmViewmodelForm },
        { provide: UIState, useClass: HzhbxxsV4dmViewmodelUIState },
        { provide: ViewModel, useClass: HzhbxxsV4dmViewmodel },
        { provide: EXCEPTION_HANDLER, useValue: null },
]
})
export class HzhbxxsV4dmComponent extends FrameComponent implements OnInit, AfterViewInit, OnDestroy {

    @HostBinding('class')
    cls = 'f-struct-wrapper ';
    public viewModel: HzhbxxsV4dmViewmodel;
    lang: string ="";
    size: any = {};
    enabledLanguageList: any[] = [];
    constructor(
        private wizardSer: WizardService,
        private keybindingService: KeybindingService,
        private langService: LangService,
        private route: ActivatedRoute,
        private router: Router,
        private rootElement: ElementRef,
        private localizationService: LocalizationService,
        private frmI18nSettingService: FrmI18nSettingService,
        private focusInvalidService: FocusInvalidService,
        private stateMachine: StateMachine,
        private sanitizer: DomSanitizer,
        public injector: Injector
    ) {
        super(injector);
        this.lang = localStorage.getItem('languageCode') || "zh-CHS";
        this.viewModel.verifycationChanged.subscribe((verifyInformations: any) => {
            this.focusInvalidService.focusInvalidInput(verifyInformations, this.rootElement);
        });

        if (this.frmI18nSettingService) {
            const i18nSetting = this.frmI18nSettingService.getSetting();
            if (i18nSetting && i18nSetting.languages && i18nSetting.languages.length > 0) {
                i18nSetting.languages.forEach((item) => {
                    this.enabledLanguageList.push({
                        code: item.code,
                        name: item.name
                    });
                });
            } else {
                console.warn("get current enable languages is null. if this occurs,please ensure the form into the framework.");
                this.enabledLanguageList.push({ "code": "en", "name": "English" });
                this.enabledLanguageList.push({ "code": "zh-CHS", "name": "中文简体" });
            }
        }
    }
    ngOnInit() {
            
        if (this.keybindingService) {
            this.viewModel.keybindingMap.forEach((keyBinding, method) => {
                this.keybindingService.register(keyBinding, () => {
                    return this.viewModel[method]();
                });
            });
        }
        this.onFormLoad(); 
    }

    ngAfterViewInit(): void {
    }

    ngOnDestroy(): void {
        // 增加表单的自我销毁
        this.context.dispose && this.context.dispose();
        this.context = null;
        this.subscription = null;
        this.declaration = null;
        this.wizardSer = null;
        this.keybindingService = null;
        this.langService = null;
        this.route = null;
        this.router = null;
        this.rootElement = null;
        this.localizationService = null;
        this.frmI18nSettingService = null;
        
        this.focusInvalidService = null;
        this.stateMachine = null;
        this.sanitizer = null;
        this.injector = null;
        this.enabledLanguageList = [];

    }

    handleSizeChange(size: any) {
        this.size = size;
    } 

    public onFormLoad() {
    } 
    tabsToolbarStates = new BehaviorSubject({});
    tabsToolbarVisibleStates = new BehaviorSubject({});
    sectionsToolbarStates = new BehaviorSubject({});
    sectionsToolbarVisibleStates = new BehaviorSubject({});
    basicFormSectionV4dm = {
        position: 'inHead',
        contents: [
        ]
    }
    Sectionbasicformsectionv4dmMainTitle = this.langService.transform("Section/basic-form-section-v4dm/mainTitle", this.lang, "合作伙伴信息");
    Sectionbasicformsectionv4dmSubTitle = this.langService.transform("Section/basic-form-section-v4dm/subTitle", this.lang, "");
    merchantName_ae1f5b58_c28h_PlaceHolder = this.langService.transform("TextBox/merchantName_ae1f5b58_c28h/placeHolder", this.lang, "");
    merchantCode_13993795_hl5j_PlaceHolder = this.langService.transform("TextBox/merchantCode_13993795_hl5j/placeHolder", this.lang, "");
    companyType_21694f08_o1ff_PlaceHolder = this.langService.transform("TextBox/companyType_21694f08_o1ff/placeHolder", this.lang, "");
    merchantType_3be4e233_ldn9_PlaceHolder = this.langService.transform("TextBox/merchantType_3be4e233_ldn9/placeHolder", this.lang, "");
    realName_6826be36_1rxr_PlaceHolder = this.langService.transform("TextBox/realName_6826be36_1rxr/placeHolder", this.lang, "");
    fullName_64a2ea29_eyqm_PlaceHolder = this.langService.transform("TextBox/fullName_64a2ea29_eyqm/placeHolder", this.lang, "");
    businessLicense_2b4ffe5d_pqq5_PlaceHolder = this.langService.transform("TextBox/businessLicense_2b4ffe5d_pqq5/placeHolder", this.lang, "");
    address_45db5c58_7l1q_PlaceHolder = this.langService.transform("TextBox/address_45db5c58_7l1q/placeHolder", this.lang, "");
    email_df58773a_cecp_PlaceHolder = this.langService.transform("TextBox/email_df58773a_cecp/placeHolder", this.lang, "");
    telephone_b5ad4b6a_4hcw_PlaceHolder = this.langService.transform("TextBox/telephone_b5ad4b6a_4hcw/placeHolder", this.lang, "");
    adminstrator_8c0cccc8_3jam_PlaceHolder = this.langService.transform("TextBox/adminstrator_8c0cccc8_3jam/placeHolder", this.lang, "");
}